﻿Imports DevComponents.DotNetBar

Public Class FrmCapturaFamilia

    Private Sub FrmCapturaFamilia_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: esta línea de código carga datos en la tabla 'DataSet_Prod_Serv.Familias' Puede moverla o quitarla según sea necesario.
        Me.FamiliasTableAdapter.Fill(Me.DataSet_Prod_Serv.Familias)
        Me.cbTipo.DataSource = Me.FamiliasTableAdapter.GetData_GrupoTipo

        'Todo esto son los colores de los controles que por alguna razón no los toma en sus propiedades del diseñador ಥ_ಥ 
        Me.BackColor = StyleManager1.MetroColorParameters.CanvasColor
        lblNombre.ForeColor = SystemColors.MenuHighlight 'Los controles no cambian su foreColor por alguna extraña razón ಥ_ಥ
        txtNombre.BackColor = StyleManager1.MetroColorParameters.CanvasColor
        txtCodigo.BackColor = StyleManager1.MetroColorParameters.CanvasColor
        cbTipo.BackColor = StyleManager1.MetroColorParameters.CanvasColor
        slideOpciones.BackColor = Color.Black
        panelOpciones.BackColor = Color.Black
        dgvFamilia.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells)
    End Sub

    Private Sub AtrasBtn_Click(sender As Object, e As EventArgs) Handles AtrasBtn.Click
        FrmCatalogo.Show()
        _EnTarea = False
        _Editar = False
        Me.Close()
    End Sub

    Private Sub btnMostrarOpciones_Click(sender As Object, e As EventArgs) Handles btnMostrarOpciones.Click
        slideOpciones.IsOpen = True
    End Sub

    Private Sub ButtonItem1_Click(sender As Object, e As EventArgs) Handles ButtonItem1.Click
        slideOpciones.IsOpen = False
    End Sub

    Private Sub txt_Enter(sender As Object, e As EventArgs) Handles txtCodigo.Enter, txtNombre.Enter
        Dim txt As DevComponents.DotNetBar.Controls.TextBoxX = DirectCast(sender, DevComponents.DotNetBar.Controls.TextBoxX)
        txt.Border.BorderColor2 = SystemColors.MenuHighlight
    End Sub

    Private Sub txt_TextChanged(sender As Object, e As EventArgs) Handles txtCodigo.TextChanged, txtNombre.TextChanged
        Dim txt As DevComponents.DotNetBar.Controls.TextBoxX = DirectCast(sender, DevComponents.DotNetBar.Controls.TextBoxX)
        If txt Is txtCodigo Then
            If txt.Text <> "" Then
                lbCodigo.Visible = True
            Else
                lbCodigo.Visible = False
            End If
        End If
        If txt Is txtNombre Then
            If txt.Text <> "" Then
                lbNombre.Visible = True
            Else
                lbNombre.Visible = False
            End If
        End If
    End Sub

    Private Sub btnCancelar_Click(sender As Object, e As EventArgs) Handles btnCancelar.Click
        Me.Close()
    End Sub

    Public Sub Limpia_Todo()
        Try
            For Each ctrl As Control In Me.Controls
                If TypeOf ctrl Is DevComponents.DotNetBar.Controls.TextBoxX Then
                    CType(ctrl, DevComponents.DotNetBar.Controls.TextBoxX).Text = String.Empty
                ElseIf TypeOf ctrl Is DevComponents.DotNetBar.Controls.ComboBoxEx Then
                    CType(ctrl, DevComponents.DotNetBar.Controls.ComboBoxEx).SelectedIndex = 0
                End If
            Next
        Catch
        End Try
    End Sub

    Private Sub btnAgregar_Click(sender As Object, e As EventArgs) Handles btnAgregar.Click
        Try
            If txtCodigo.Text = "" Or txtNombre.Text = "" Or cbTipo.Text = "" Then
                ToastNotification.Show(Me, "Debe de capturar los 3 campos de la familia para poder guardarla.", My.Resources.appbar_cone, 5000, eToastGlowColor.Red, eToastPosition.MiddleCenter)
                Exit Sub
            End If
            If _Editar = False Then
                familia.Insert(txtCodigo.Text, txtNombre.Text, cbTipo.Text)
                ToastNotification.Show(Me, "Capturado con exito", My.Resources.add2, 4000, eToastGlowColor.Blue, eToastPosition.TopCenter)
                FrmCapturaFamilia_Load(Nothing, Nothing)
            End If
        Catch ex As Exception
            ToastNotification.Show(Me, ex.Message, My.Resources.appbar_cone, 5000, eToastGlowColor.Red, eToastPosition.MiddleCenter)
        End Try
        Limpia_Todo()
    End Sub


    Private Sub cbTipo_KeyPress(sender As Object, e As KeyPressEventArgs) Handles cbTipo.KeyPress
        e.KeyChar = e.KeyChar.ToString.ToUpper
    End Sub

    Private Sub dgvFamilia_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvFamilia.CellDoubleClick
        Try
            _IDFAMILIA = Me.dgvFamilia.CurrentRow.Cells(0).Value
            txtCodigo.Text = Me.dgvFamilia.CurrentRow.Cells(1).Value
            txtNombre.Text = Me.dgvFamilia.CurrentRow.Cells(2).Value
            cbTipo.Text = Me.dgvFamilia.CurrentRow.Cells(3).Value
            Me.dgvFamilia.CurrentRow.DefaultCellStyle.BackColor = Color.MediumVioletRed
        Catch ex As Exception
            ToastNotification.Show(Me, ex.Message, My.Resources.appbar_cone, 5000, eToastGlowColor.Red, eToastPosition.MiddleCenter)
        End Try
    End Sub

    Private Sub btnActualizar_Click(sender As Object, e As EventArgs) Handles btnActualizar.Click
        Try
            familia.Update(txtCodigo.Text, txtNombre.Text, cbTipo.Text, _IDFAMILIA)
            ToastNotification.Show(Me, "Actualizado con exito", My.Resources.add1, 4000, eToastGlowColor.Blue, eToastPosition.TopCenter)
            FrmCapturaFamilia_Load(Nothing, Nothing)
        Catch ex As Exception
            ToastNotification.Show(Me, ex.Message, My.Resources.appbar_cone, 5000, eToastGlowColor.Red, eToastPosition.MiddleCenter)
        End Try
    End Sub
End Class